package main

import (
	"fmt"
	"strconv"
)

// 演示golang 基本数据类型转string
func main() {

	var i int = 12
	var f float32 = 12.2
	var b bool = false
	var by byte = 'H'

	//方式1
	var str string
	str = fmt.Sprintf("%d", i)
	fmt.Printf("type %T, value %q\n", str, str)

	str = fmt.Sprintf("%f", f)
	fmt.Printf("type %T, value %q\n", str, str)

	str = fmt.Sprintf("%t", b)
	fmt.Printf("type %T, value %q\n", str, str)

	str = fmt.Sprintf("%c", by)
	fmt.Printf("type %T, value %q\n", str, str)

	fmt.Println()
	//方式二
	str = strconv.FormatInt(int64(i), 10)
	fmt.Printf("type %T, value %q\n", str, str)

	itoa := strconv.Itoa(i)
	fmt.Printf("type %T, value %q\n", itoa, itoa)

	str = strconv.FormatFloat(float64(f), 'f', 10, 64)
	fmt.Printf("type %T, value %q\n", str, str)

	str = strconv.FormatBool(b)
	fmt.Printf("type %T, value %q\n", str, str)

}
